from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-13 14:12:30.510328
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 13, Aug, 2021
Time: 14:12:34
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6109
Nobs: 382.000 HQIC: -46.1717
Log likelihood: 4100.91 FPE: 6.13472e-21
AIC: -46.5404 Det(Omega_mle): 4.86173e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.450051 0.096970 4.641 0.000
L1.Burgenland 0.109845 0.049901 2.201 0.028
L1.Kärnten -0.116538 0.024473 -4.762 0.000
L1.Niederösterreich 0.164825 0.106854 1.543 0.123
L1.Oberösterreich 0.114724 0.105636 1.086 0.277
L1.Salzburg 0.292804 0.051861 5.646 0.000
L1.Steiermark 0.014419 0.068779 0.210 0.834
L1.Tirol 0.123901 0.054253 2.284 0.022
L1.Vorarlberg -0.114438 0.048908 -2.340 0.019
L1.Wien -0.033552 0.094877 -0.354 0.724
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.008117 0.229008 -0.035 0.972
L1.Burgenland -0.046040 0.117848 -0.391 0.696
L1.Kärnten 0.034756 0.057797 0.601 0.548
L1.Niederösterreich -0.246339 0.252350 -0.976 0.329
L1.Oberösterreich 0.555361 0.249474 2.226 0.026
L1.Salzburg 0.313280 0.122476 2.558 0.011
L1.Steiermark 0.111238 0.162432 0.685 0.493
L1.Tirol 0.301815 0.128126 2.356 0.018
L1.Vorarlberg -0.013110 0.115503 -0.114 0.910
L1.Wien 0.009859 0.224066 0.044 0.965
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.257067 0.049608 5.182 0.000
L1.Burgenland 0.095593 0.025528 3.745 0.000
L1.Kärnten -0.003291 0.012520 -0.263 0.793
L1.Niederösterreich 0.230226 0.054664 4.212 0.000
L1.Oberösterreich 0.152836 0.054041 2.828 0.005
L1.Salzburg 0.038464 0.026531 1.450 0.147
L1.Steiermark 0.010629 0.035186 0.302 0.763
L1.Tirol 0.074071 0.027755 2.669 0.008
L1.Vorarlberg 0.057781 0.025020 2.309 0.021
L1.Wien 0.087412 0.048537 1.801 0.072
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191600 0.048468 3.953 0.000
L1.Burgenland 0.043010 0.024942 1.724 0.085
L1.Kärnten -0.006772 0.012232 -0.554 0.580
L1.Niederösterreich 0.123981 0.053408 2.321 0.020
L1.Oberösterreich 0.312880 0.052800 5.926 0.000
L1.Salzburg 0.101969 0.025921 3.934 0.000
L1.Steiermark 0.138687 0.034378 4.034 0.000
L1.Tirol 0.076474 0.027117 2.820 0.005
L1.Vorarlberg 0.055267 0.024446 2.261 0.024
L1.Wien -0.038043 0.047422 -0.802 0.422
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.202386 0.096770 2.091 0.036
L1.Burgenland -0.061006 0.049798 -1.225 0.221
L1.Kärnten -0.036800 0.024423 -1.507 0.132
L1.Niederösterreich 0.087105 0.106633 0.817 0.414
L1.Oberösterreich 0.195745 0.105418 1.857 0.063
L1.Salzburg 0.264616 0.051754 5.113 0.000
L1.Steiermark 0.075454 0.068637 1.099 0.272
L1.Tirol 0.124132 0.054141 2.293 0.022
L1.Vorarlberg 0.116333 0.048807 2.384 0.017
L1.Wien 0.036303 0.094682 0.383 0.701
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.036473 0.075699 0.482 0.630
L1.Burgenland 0.025543 0.038955 0.656 0.512
L1.Kärnten 0.050517 0.019105 2.644 0.008
L1.Niederösterreich 0.194061 0.083415 2.326 0.020
L1.Oberösterreich 0.344114 0.082464 4.173 0.000
L1.Salzburg 0.049071 0.040485 1.212 0.225
L1.Steiermark -0.002473 0.053692 -0.046 0.963
L1.Tirol 0.116313 0.042352 2.746 0.006
L1.Vorarlberg 0.062097 0.038180 1.626 0.104
L1.Wien 0.125484 0.074066 1.694 0.090
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169515 0.092116 1.840 0.066
L1.Burgenland 0.023040 0.047403 0.486 0.627
L1.Kärnten -0.058088 0.023248 -2.499 0.012
L1.Niederösterreich -0.111206 0.101505 -1.096 0.273
L1.Oberösterreich 0.192494 0.100348 1.918 0.055
L1.Salzburg 0.030165 0.049265 0.612 0.540
L1.Steiermark 0.302414 0.065336 4.629 0.000
L1.Tirol 0.492878 0.051537 9.563 0.000
L1.Vorarlberg 0.067051 0.046460 1.443 0.149
L1.Wien -0.104920 0.090128 -1.164 0.244
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161397 0.100455 1.607 0.108
L1.Burgenland -0.004865 0.051694 -0.094 0.925
L1.Kärnten 0.062497 0.025353 2.465 0.014
L1.Niederösterreich 0.192787 0.110694 1.742 0.082
L1.Oberösterreich -0.124255 0.109433 -1.135 0.256
L1.Salzburg 0.245334 0.053725 4.566 0.000
L1.Steiermark 0.156832 0.071251 2.201 0.028
L1.Tirol 0.051139 0.056203 0.910 0.363
L1.Vorarlberg 0.122258 0.050666 2.413 0.016
L1.Wien 0.140088 0.098288 1.425 0.154
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.506280 0.054437 9.300 0.000
L1.Burgenland -0.019118 0.028014 -0.682 0.495
L1.Kärnten -0.009177 0.013739 -0.668 0.504
L1.Niederösterreich 0.191979 0.059986 3.200 0.001
L1.Oberösterreich 0.260542 0.059303 4.393 0.000
L1.Salzburg 0.022994 0.029114 0.790 0.430
L1.Steiermark -0.026750 0.038612 -0.693 0.488
L1.Tirol 0.070127 0.030457 2.303 0.021
L1.Vorarlberg 0.057920 0.027456 2.110 0.035
L1.Wien -0.052711 0.053263 -0.990 0.322
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.019347 0.064881 0.137267 0.124965 0.035290 0.066222 -0.002996 0.184068
Kärnten 0.019347 1.000000 -0.055286 0.128934 0.045712 0.069709 0.458692 -0.093190 0.099826
Niederösterreich 0.064881 -0.055286 1.000000 0.289365 0.089390 0.272799 0.013303 0.146492 0.255764
Oberösterreich 0.137267 0.128934 0.289365 1.000000 0.174438 0.294659 0.163065 0.119315 0.137036
Salzburg 0.124965 0.045712 0.089390 0.174438 1.000000 0.129075 0.048706 0.107357 0.052276
Steiermark 0.035290 0.069709 0.272799 0.294659 0.129075 1.000000 0.129008 0.087105 -0.025328
Tirol 0.066222 0.458692 0.013303 0.163065 0.048706 0.129008 1.000000 0.036512 0.125788
Vorarlberg -0.002996 -0.093190 0.146492 0.119315 0.107357 0.087105 0.036512 1.000000 -0.048042
Wien 0.184068 0.099826 0.255764 0.137036 0.052276 -0.025328 0.125788 -0.048042 1.000000